﻿function ProgressDialog(TimeOut) {
    if (TimeOut) {
        this.ProgressBar_TimeOut = TimeOut;
    }
    else {
        this.ProgressBar_TimeOut = 60000;
    }

    window.ProgressBar_Count;
    this.ProgressBar_Interval;

    this.StopProgressBar = function () {
        window.clearInterval(this.ProgressBar_Interval);
        $("#ProgressBar_Dialog").dialog("close");
    };

    this.StartProgressBar = function () {
        window.ProgressBar_Count = 0;
        $("#ProgressBar_Dialog").dialog("open");
        $("#ProgressBar").progressbar({ value: window.ProgressBar_Count++ });
        this.ProgressBar_Interval = window.setInterval("if (window.ProgressBar_Count < 100) { $('#ProgressBar').progressbar('value', window.ProgressBar_Count++); }", this.ProgressBar_TimeOut / 100);
    };

    $(function () {
        var div = document.createElement("div");
        div.id = "ProgressBar_Dialog";
        div.title = "正在处理数据，请稍等…";
        div.innerHTML = "<div id=\"ProgressBar\" style=\"margin:20px 10px 0 10px;\"></div>";
        document.body.appendChild(div);

        $("#ProgressBar_Dialog").dialog({
            autoOpen: false,
            resizable: false,
            height: 105,
            width: 240,
            modal: true,
            zIndex: 1500
        });
    });
}

/* --------------------------------------------------------------------------------------------------- */

function InfoDialog() {
    this.OpenDialog = function (Content, Icon, ComfigHandle, CloseHandle) {
        document.getElementById("InfoDialog_Content").innerHTML = Content;
        document.getElementById("InfoDialog_Icon").src = "/Content/Frame/Icon/Sign_" + Icon + ".png";
        if (ComfigHandle != undefined && ComfigHandle != null) {
            $("#InfoDialog_Dialog").dialog({
                autoOpen: true,
                resizable: false,
                height: 186,
                width: 340,
                modal: true,
                zIndex: 2000,
                buttons: {
                    "确认": ComfigHandle,
                    "取消": function () {
                        $(this).dialog("close");
                        if (CloseHandle != undefined && CloseHandle != null) {
                            CloseHandle();
                        }
                    }
                }
            });
        } else {
            $("#InfoDialog_Dialog").dialog({
                autoOpen: true,
                resizable: false,
                height: 186,
                width: 340,
                modal: true,
                zIndex: 2000,
                buttons: {
                    "关闭": function () {
                        $(this).dialog("close");
                        if (CloseHandle != undefined && CloseHandle != null) {
                            CloseHandle();
                        }
                    }
                }
            });
        }
    };

    this.CloseDialog = function () {
        $("#InfoDialog_Dialog").dialog("close");
    };

    $(function () {
        var div = document.createElement("div");
        div.id = "InfoDialog_Dialog";
        div.title = "系统信息";
        div.innerHTML = "<table cellpadding=\"0\" cellspacing=\"15\" border=\"0\"><tr><td><img id=\"InfoDialog_Icon\" src=\"\" /></td><td id=\"InfoDialog_Content\" valign=\"top\"></td></tr></table>";
        document.body.appendChild(div);
        $("#InfoDialog_Dialog").css("display", "none");
    });
}

/* --------------------------------------------------------------------------------------------------- */

function SelectOption() {
    this.SelectList = function (ElementID, ItemList, SelectID, SelectValue, ShowID) {
        if (ItemList != null) {
            var Select = document.getElementById(ElementID);
            var Option;
            for (var i = 0; i < ItemList.length; i++) {
                Option = document.createElement("option");
                Option.value = ItemList[i][0];
                if (ShowID) {
                    Option.innerHTML = ItemList[i][1] + "(" + ItemList[i][0] + ")";
                } else {
                    Option.innerHTML = ItemList[i][1];
                }
                if (ItemList[i][0] == SelectID || ItemList[i][1] == SelectValue) {
                    Option.selected = true;
                }
                Select.appendChild(Option);
            }
        }
    }
}

/* --------------------------------------------------------------------------------------------------- */

function ActivityItem(SelfObjName, ItemHtmlSelecter, AIconSelecter, ItemPanelID, Preorder, Postorder, AddFunction, DeleteFunction, SortItem) {
    this.selfObjName = SelfObjName;
    this.itemHtmlSelecter = ItemHtmlSelecter;
    this.aIconSelecter = AIconSelecter;
    this.itemPanelID = ItemPanelID;
    this.addFunction = AddFunction;
    this.deleteFunction = DeleteFunction;
    this.AddItem = function () {
        if (this.aIconSelecter != null && this.aIconSelecter != "")
            $(this.aIconSelecter).css("visibility", "visible");
        $("#" + this.itemPanelID).append(Preorder + $(this.itemHtmlSelecter).html().replace(/DeleteItem\(/ig, "window." + SelfObjName + ".DeleteItem(").replace(/AddItem\(/ig, "window." + SelfObjName + ".AddItem(").replace(/#itemPanelID/ig, "#" + this.itemPanelID) + Postorder);
        if (this.addFunction != null) {
            this.addFunction();
        }
    }
    this.DeleteItem = function (evenObj) {
        var ParentObj = $(evenObj).parent();
        do {
            var ParentObj = $(ParentObj).parent();
        } while ($(ParentObj).parent().attr("id") != this.itemPanelID)

        $(ParentObj).remove();
        if (this.deleteFunction != null) {
            this.deleteFunction(evenObj);
        }
    }
    if (SortItem) {
        $("#" + this.itemPanelID).sortable({ handle: ".ItemHandle" });
    }
}     

/* --------------------------------------------------------------------------------------------------- */

function TabClass(SelfObjName, TabID, TabTitleIDs, TabContentIDs, TabTitleFunctions) {
    this.selfObjName = SelfObjName;
    this.tabID = TabID;
    this.tabTitleIDs = TabTitleIDs;
    this.tabContentIDs = TabContentIDs;
    this.tabTitleFunctions = TabTitleFunctions;

    this.Show = function (index) {
        for (var i = 0; i < this.tabContentIDs.length; i++) {
            if (index == i) {
                $("#" + this.tabContentIDs[i]).css("display", "");
            } else {
                $("#" + this.tabContentIDs[i]).css("display", "none");
            }
        }
    }
    $("#" + TabID).buttonset();
    this.Show(0);

    var Temp = "#" + TabTitleIDs[0];
    for (var i = 1; i < TabTitleIDs.length; i++) {
        Temp += ",#" + TabTitleIDs[i];
    }
    $(Temp).each(function (index, element) {
        if (TabTitleFunctions != null) {
            eval("$(element).change(function () { $(element).blur(); if(window." + SelfObjName + ".tabTitleFunctions[" + index + "] != null){ window." + SelfObjName + ".tabTitleFunctions[" + index + "](index); } else { window." + SelfObjName + ".Show(" + index + "); } });");
        } else {
            eval("$(element).change(function () { $(element).blur(); window." + SelfObjName + ".Show(" + index + "); });");
        }
    });
}

/* --------------------------------------------------------------------------------------------------- */

function UploadifyClass(UploadifyID, Uploader, ButtonText, TypeDesc, TypeExts, FileSizeLimit, FormData, onUploadSuccess) {
    FormData["SID"] = JsonOriginal.SID;
    $('#' + UploadifyID).uploadify({
        'swf': '/Content/Uploadify/uploadify.swf',
        'uploader': Uploader,
        'buttonText': ButtonText,
        'fileTypeDesc': TypeDesc,
        'fileTypeExts': TypeExts,
        'fileSizeLimit': FileSizeLimit,
        'formData': FormData,
        'onUploadError': function (file, errorCode, errorMsg, errorString) {
        },
        'onUploadSuccess': function (file, data, response) {
            onUploadSuccess(file, data, response);
        }
    });
}

/* --------------------------------------------------------------------------------------------------- */

function AjaxClass() {
    this.AjaxSubmit = function (Action, Data, SuccessDelayCode, SuccessCode, ErrorCode, ShowDialog, DelayCloseDialog) {
        $.ajax({
            url: Action,
            type: "POST",
            timeout: 60000,
            data: Data,
            dataType: 'json',
            beforeSend: function (data) {
                progressDialog.StartProgressBar();
            },
            success: function (data, text) {
                if (data.Success) {
                    progressDialog.StopProgressBar();
                    if (ShowDialog) {
                        infoDialog.OpenDialog(data.Message, "Select");
                        if (DelayCloseDialog) {
                            window.setTimeout("infoDialog.CloseDialog()", 800);
                        }
                    }
                    if (SuccessDelayCode != null && SuccessDelayCode != "") {
                        window.setTimeout(SuccessDelayCode, 800);
                    }
                    if (SuccessCode != null && SuccessCode != "") {
                        eval(SuccessCode);
                    }
                } else {
                    if (ErrorCode != null && ErrorCode != "" && ErrorCode != undefined) {
                        eval(ErrorCode);
                    }
                    progressDialog.StopProgressBar();
                    infoDialog.OpenDialog(data.Message, "Error");
                }
            },
            error: function (data, text) {
                if (ErrorCode != null && ErrorCode != "" && ErrorCode != undefined) {
                    eval(ErrorCode);
                }
                progressDialog.StopProgressBar();
                if (text != "timeout") {
                    infoDialog.OpenDialog("处理数据时出错，请与系统管理员联系！", "Error");
                } else {
                    infoDialog.OpenDialog("处理数据超出了一般所需时间，无法判断该操作是否完成！", "Error");
                }
            }
        });
    }
}

/* --------------------------------------------------------------------------------------------------- */

function ResizeFlexiGrid(WidthSelecter, DataTableSelecter, HeightSelecter, HeightCutSelecters, BorderWidth, BorderHeight, FixHeight) {
    this.widthSelecter = WidthSelecter;
    this.dataTableSelecter = DataTableSelecter;
    this.heightSelecter = HeightSelecter;
    this.heightCutSelecters = HeightCutSelecters;
    this.borderWidth = BorderWidth;
    this.borderHeight = BorderHeight;
    this.fixHeight = FixHeight;
    this.MinWidth = function () { if (this.widthSelecter != "" && this.widthSelecter != null) { $(this.widthSelecter).css("width", "0px"); } }
    this.MinHeight = function () { if (this.heightSelecter != "" && this.heightSelecter != null) { $(this.heightSelecter).css("height", "0px"); } }
    this.Width = function () { if (this.widthSelecter != "" && this.widthSelecter != null) { $(this.widthSelecter).css("width", ($(window).width() - this.borderWidth * 2) + "px"); } }
    this.Height = function () {
        if (this.heightSelecter != "" && this.heightSelecter != null) {
            var MaxHeight = $(window).height() - (this.heightCutSelecters.length + 1) * this.borderHeight - 1;
            if (this.fixHeight != undefined && this.fixHeight != null) {
                MaxHeight += this.fixHeight;
            }
            for (var i = 0; i < this.heightCutSelecters.length; i++) {
                MaxHeight -= $(this.heightCutSelecters[i]).outerHeight(true);
            }
            if ($(this.dataTableSelecter).outerHeight(true) > MaxHeight) {
                $(this.heightSelecter).css("height", MaxHeight + "px");
            } else {
                $(this.heightSelecter).css("height", "100%");
            }
        }
    }
    this.Resize = function (ObjName) {
        eval("$(window).resize(function () { window." + ObjName + ".MinWidth(); window." + ObjName + ".MinHeight(); window." + ObjName + ".Width(); window." + ObjName + ".Height(); });");        
    }
}

/* --------------------------------------------------------------------------------------------------- */

function FieldsClass() {
    this.CheckForm = function (Selecters, DateLists, DateError) {
        var CheckOK = true;
        for (var i = 0; i < Selecters.length; i++) {
            $("#" + Selecters[i] + " input.Required").each(function (index, element) { if ($(element).val() == "") { CheckOK = false; } });
        }
        if (CheckOK) {
            if (DateLists != undefined) {
                for (var i = 0; i < DateLists.length; i++) {
                    if ($("#" + DateLists[i].StartDate).size() > 0) {
                        if (window.dateControl.CheckDateControl("#" + DateLists[i].StartDate)) {
                            if (DateLists[i].StopDate != undefined) {
                                if ($("#" + DateLists[i].StopDate).size() > 0) {
                                    if (window.dateControl.CheckDateControl("#" + DateLists[i].StopDate)) {
                                        if ($("#" + DateLists[i].StopDate).val() < $("#" + DateLists[i].StartDate).val()) {
                                            infoDialog.OpenDialog('结束时间不应小于开始时间！', 'Alert', null, function () { eval(DateError); $("#" + DateLists[i].StopDate).focus(); });
                                            CheckOK = false;
                                            break;
                                        }
                                    } else {
                                        CheckOK = false;
                                        break;
                                    } 
                                }
                            }
                        } else {
                            CheckOK = false;
                            break;
                        }
                    }
                }
            }
        } else {
            infoDialog.OpenDialog('请完成必填项目的填写！', 'Alert', null, function () { window.tabClass.Show(0); $("label[for='radio1']").click(); });
        }
        return CheckOK;
    }
    this.FillParameters = function (Parameters, FieldObj) {
        var P = {};
        for (var i in Parameters) {
            switch ($("#" + Parameters[i]).attr("type")) {
                case "checkbox":
                    P[i] = $("#" + Parameters[i]).is(":checked")
                    break;
                default:
                    if ($("#" + Parameters[i]).val() == "" && $("#" + Parameters[i]).attr("emptynull") != undefined) {
                        P[i] = null;
                    } else {
                        P[i] = $("#" + Parameters[i]).val();
                    }
                    break;
            }
        }
        return P;
    }
    this.FillDetailParameters = function (element, Parameters) {
        var P = {};
        for (var i in Parameters) {
            if ($(element).find(" td[abbr=" + Parameters[i] + "] div input").size() == 1) {
                P[i] = $(element).find("td[abbr=" + Parameters[i] + "] div input").val();
            } else {
                P[i] = $(element).find("td[abbr=" + Parameters[i] + "] div").text();
            }
        }
        return P;
    }
    this.AddFields = function (Selecter, FieldObj) {
        if (window.dateControl == undefined) {
            window.dateControl = new DateControl("DateControl");
        }
        window.dateControl.dateContorls = new Array();
        if (window.autoComplete == undefined) {
            window.autoComplete = new AutoComplete();
        }
        for (var i = 0; i < FieldObj.Fields.length; i++) {
            var Value = (FieldObj.Fields[i].DefautlValue != undefined && FieldObj.Fields[i].DefautlValue != "") ? FieldObj.Fields[i].DefautlValue : "";
            if (JsonOriginal.Operations[FieldObj.OperationKey].OperationData != null) {
                Value = JsonOriginal.Operations["浏览主表"].OperationData[0][FieldObj.Fields[i].DataField];
            }
            switch (Value) {
                case "#ToDay":
                    if (FieldObj.Fields[i].Type != "Date") { Value = (new Date).pattern("yyyy-MM-dd"); }
                    break;
                case "#UserID":
                    Value = JsonOriginal.UserID;
                    break;
                case "#UserName":
                    Value = JsonOriginal.UserName;
                    break;
                case null:
                    Value = "";
                    break;
            }
            if ($("#" + FieldObj.Fields[i].ID).size() > 0) {
                $("#" + FieldObj.Fields[i].ID).text(Value);
            } else {
                switch (FieldObj.Fields[i].Type) {
                    case "Hidden":
                        $(Selecter).append("<input type=\"hidden\" id=\"" + FieldObj.Fields[i].ID + "\" value=\"" + Value + "\" />");
                        break;
                    case "Text":
                        if (FieldObj.Fields[i].Regexp != undefined && FieldObj.Fields[i].Regexp != null) {
                            $(Selecter).append("<div class=\"Panel\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"Name\">" + FieldObj.Fields[i].ShowName + "</td><td class=\"Input\"><input type=\"text\" value=\"" + Value + "\" title=\"" + Value + "\" onblur=\"Regexp=" + FieldObj.Fields[i].Regexp + ";if(this.value != '' && !Regexp.test(this.value)){infoDialog.OpenDialog('输入格式错误，当前输入必须是浮点数！', 'Error', null, function () { $('#" + FieldObj.Fields[i].ID + "').focus(); });}\" id=\"" + FieldObj.Fields[i].ID + "\"" + ((FieldObj.Fields[i].OperationKey != undefined && FieldObj.Fields[i].OperationKey != "") ? " lang=\"" + FieldObj.Fields[i].OperationKey + "\"" : "") + (FieldObj.Fields[i].Readonly ? " readonly=\"readonly\"" : "") + (FieldObj.Fields[i].Required ? " class=\"Required\"" : "") + (FieldObj.Fields[i].EmptyNull ? " emptynull=\"emptynull\"" : "") + " style=\"" + ((FieldObj.Fields[i].Width != undefined && FieldObj.Fields[i].Width != "") ? "width:" + FieldObj.Fields[i].Width + "px;" : "") + ((FieldObj.Fields[i].Height != undefined && FieldObj.Fields[i].Height != "") ? "height:" + FieldObj.Fields[i].Height + "px;" : "") + "\" /></td></tr></table></div>");
                        } else {
                            $(Selecter).append("<div class=\"Panel\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"Name\">" + FieldObj.Fields[i].ShowName + "</td><td class=\"Input\"><input type=\"text\" value=\"" + Value + "\" title=\"" + Value + "\" id=\"" + FieldObj.Fields[i].ID + "\"" + ((FieldObj.Fields[i].OperationKey != undefined && FieldObj.Fields[i].OperationKey != "") ? " lang=\"" + FieldObj.Fields[i].OperationKey + "\"" : "") + (FieldObj.Fields[i].Readonly ? " readonly=\"readonly\"" : "") + (FieldObj.Fields[i].Required ? " class=\"Required\"" : "") + (FieldObj.Fields[i].EmptyNull ? " emptynull=\"emptynull\"" : "") + " style=\"" + ((FieldObj.Fields[i].Width != undefined && FieldObj.Fields[i].Width != "") ? "width:" + FieldObj.Fields[i].Width + "px;" : "") + ((FieldObj.Fields[i].Height != undefined && FieldObj.Fields[i].Height != "") ? "height:" + FieldObj.Fields[i].Height + "px;" : "") + "\" /></td></tr></table></div>");
                        }
                        break;
                    case "Checkbox":
                        $(Selecter).append("<div class=\"Panel\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"Name\">" + FieldObj.Fields[i].ShowName + "</td><td class=\"Input\" style=\"width:" + (FieldObj.Fields[i].Width + 6) + "px\"><input value=\"" + Value + "\" id=\"" + FieldObj.Fields[i].ID + "\" type=\"checkbox\"" + (FieldObj.Fields[i].Readonly ? " disabled=\"disabled\"" : "") + (Value ? " checked=\"checked\"" : "") + " /></td></tr></table></div>");
                        break;
                    case "Date":
                        $(Selecter).append("<div class=\"Panel\"><table cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"Name\">" + FieldObj.Fields[i].ShowName + "</td><td class=\"Input\"><input type=\"text\" id=\"" + FieldObj.Fields[i].ID + "\"" + (FieldObj.Fields[i].Readonly ? " readonly=\"readonly\"" : "") + (FieldObj.Fields[i].Required ? " class=\"Required\"" : "") + (FieldObj.Fields[i].EmptyNull ? " emptynull=\"emptynull\"" : "") + " style=\"" + ((FieldObj.Fields[i].Width != undefined && FieldObj.Fields[i].Width != "") ? "width:" + FieldObj.Fields[i].Width + "px;" : "") + ((FieldObj.Fields[i].Height != undefined && FieldObj.Fields[i].Height != "") ? "height:" + FieldObj.Fields[i].Height + "px;" : "") + "\" /></td></tr></table></div>");
                        if (Value == "#ToDay") {
                            window.dateControl.dateContorls.push({ "Selecter": "#" + FieldObj.Fields[i].ID, "DefaultDate": new Date });
                        } else {
                            window.dateControl.dateContorls.push({ "Selecter": "#" + FieldObj.Fields[i].ID });
                            if (Value != "") {
                                $("#" + FieldObj.Fields[i].ID).val(Value);
                            }
                        }
                        break;
                    case "Amount":
                        $("#ButtonTR .ButtonUnit").append("<span style=\"margin-left:12px;vertical-align: -1px;\" class=\"AmountTitle\">" + FieldObj.Fields[i].ShowName + "：</span><span id=\"" + FieldObj.Fields[i].ID + "\" style=\"margin-right:4px;vertical-align: -1px;\" class=\"Amount\">" + Value + "</span>");
                        break;
                    case "ConfirmAmount":
                        $("#ButtonTR .ButtonUnit").append("<span style=\"margin-left:12px;vertical-align: -1px;\" class=\"AmountTitle\">" + FieldObj.Fields[i].ShowName + "：</span><span id=\"" + FieldObj.Fields[i].ID + "\" style=\"margin-right:4px;vertical-align: -1px;\" class=\"ConfirmAmount\">" + Value + "</span>");
                        break;
                }
            }
            if (FieldObj.Fields[i].LineBreak) {
                $(Selecter).append("<div class=\"Clear\"></div>");
            }
        }
        window.dateControl.SetDateControl();
    }
    this.AddListDetails = function (ListID, OperationKey, ListCols) {
        var Values;
        for (var i = 0; i < JsonOriginal.Operations[OperationKey].OperationData.length; i++) {
            Values = new Array();
            for (var j = 0; j < ListCols.length; j++) {
                if (ListCols[j].name != "Operation") {
                    Values.push(JsonOriginal.Operations[OperationKey].OperationData[i][ListCols[j].name]);
                }
            }
            Values.push("Delete");
            window.fieldsClass.AddListDetail(ListID, window.ListDetailCols, Values);
        }
        $('#' + ListID + ' tr:odd').addClass('erow');
        $('#' + ListID + ' tr:even').removeClass('erow');
    }
    this.AddListDetail = function (ListID, ListCols, Values, BeforeSelecter) {
        if (BeforeSelecter != undefined && BeforeSelecter != null) {
            $(BeforeSelecter).before("<tr class=\"AddListDetail\"></tr>");
        } else {
            $("#" + ListID).append("<tr class=\"AddListDetail\"></tr>");
        }
        var Inner = ""; var InText = "";
        for (var i = 0; i < ListCols.length; i++) {
            if (Values != undefined && Values != null) {
                if (i < Values.length) {
                    InText = Values[i];
                } else {
                    InText = "";
                }
            }
            switch (ListCols[i].InputType) {
                case null:
                    Inner = "<div style=\"text-align: " + ListCols[i].align + "; width: " + ListCols[i].width + "px;\" title=\"" + InText + "\">" + InText + "</div>";
                    break;
                case "Text":
                    if (InText == "&nbsp;") { InText = ""; }
                    if (ListCols[i].Regexp != undefined && ListCols[i].Regexp != null) {
                        Inner = "<div style=\"width: " + (ListCols[i].width + 7) + "px; padding:3px 0 0 3px;\" title=\"" + InText + "\"><input id=\"" + (ListCols[i].InputID != undefined && ListCols[i].InputID != null ? ListCols[i].InputID : Values[1] + ListCols[i].name) + "\"" + (ListCols[i].OperationKey != undefined && ListCols[i].OperationKey != null ? "lang=\"" + ListCols[i].OperationKey + "\"" : "") + " onblur=\"Regexp=" + ListCols[i].Regexp + ";if(this.value != '' && !Regexp.test(this.value)){infoDialog.OpenDialog('" + ListCols[i].RegexpError + "', 'Error', null, function () { $('#" + Values[1] + ListCols[i].name + "').focus(); });}else{" + (ListCols[i].AutoMath != undefined ? "window.autoMath.AutoMath(this, " + ListCols[i].AutoMath + ");" : "") + "}\" class=\"" + ListCols[i].InputCalss + "\" type=\"text\" name=\"" + ListCols[i].name + "\" style=\"text-align: " + ListCols[i].align + "; width: " + (ListCols[i].width - 3) + "px;\" value=\"" + InText + "\"></div>";
                    } else {
                        Inner = "<div style=\"width: " + (ListCols[i].width + 7) + "px; padding:3px 0 0 3px;\" title=\"" + InText + "\"><input id=\"" + (ListCols[i].InputID != undefined && ListCols[i].InputID != null ? ListCols[i].InputID : Values[1] + ListCols[i].name) + "\"" + (ListCols[i].OperationKey != undefined && ListCols[i].OperationKey != null ? "lang=\"" + ListCols[i].OperationKey + "\"" : "") + " class=\"" + ListCols[i].InputCalss + "\" type=\"text\" name=\"" + ListCols[i].name + "\" style=\"text-align: " + ListCols[i].align + "; width: " + (ListCols[i].width - 3) + "px;\" value=\"" + InText + "\"></div>";
                    }
                    break;
            }
            if (ListCols[i].name == "Operation") {
                switch (InText) {
                    case "Delete":
                        Inner = "<div style=\"text-align: " + ListCols[i].align + "; width: " + ListCols[i].width + "px;\"><a href=\"javascript:CancelDetail(" + Values[1] + ")\" class=\"Operation\">取消</a></div>";
                        break;
                }
            }
            $("#" + ListID + " .AddListDetail").append("<td align=\"" + ListCols[i].align + "\" abbr=\"" + ListCols[i].name + "\"" + (ListCols[i].hide ? " style=\"display: none;\"" : "") + ">" + Inner + "</td>");
        }
        $("#" + ListID + " .AddListDetail").removeClass("AddListDetail");
    }
}                           

/* --------------------------------------------------------------------------------------------------- */

function FlexiGrid(SelfObjName, ListID, ListTDID, PageTRID, SearchTRID, ResizeObjName, ColModel, ListName, SortName, SortOrder, SearchKey, IconButton, PageType, FillListDataEnd) {
    this.selfObjName = SelfObjName;
    this.listID = ListID;
    this.listTDID = ListTDID;
    this.pageTRID = PageTRID;
    this.searchTRID = SearchTRID;
    this.resizeObjName = ResizeObjName;
    this.colModel = ColModel;
    this.listName = ListName;
    this.sortName = SortName;
    this.sortOrder = SortOrder;
    this.searchKey = SearchKey;
    this.iconButton = IconButton;
    this.pageType = PageType;
    this.fillListDataComplete = FillListDataEnd;
    //隐藏列
    this.HiddCols = function (Cols) {
        for (var i = 0; i < Cols.length; i++) {
            $("#" + this.listTDID + " .flexigrid .hDiv th:eq(" + Cols[i] + ")").css("display", "none").removeAttr("hidden");
            eval("$('#" + this.listID + " tr').each(function (index, element) { $(element).find('td:eq(" + Cols[i] + ")').css('display', 'none'); });");
        }
    }
    //显示列
    this.ShowCols = function (Cols) {
        for (var i = 0; i < Cols.length; i++) {
            $("#" + this.listTDID + " .flexigrid .hDiv th:eq(" + Cols[i] + ")").css("display", "block").removeAttr("style").attr("hidden");
            eval("$('#" + this.listID + " tr').each(function (index, element) { $(element).find('td:eq(" + Cols[i] + ")').css('display', 'block').removeAttr('style'); });");
        }
    }
    //设置列宽
    this.WidthCols = function (Cols) {
        for (var i = 0; i < Cols.length; i++) {
            $("#" + this.listTDID + " .flexigrid .hDiv th:eq(" + Cols[i].Index + ") div").css("width", (Cols[i].TheadWidth != undefined && Cols[i].TheadWidth != null ? Cols[i].TheadWidth : Cols[i].Width));
            eval("$('#" + this.listID + " tr').each(function (index, element) { $(element).find('td:eq(" + Cols[i].Index + ") div').css('width', ($(element).find('td:eq(" + Cols[i].Index + ") div input[type=text]').size() > 0 ? (" + Cols[i].Width + " + 7) : " + Cols[i].Width + ")); });");
        }
    }
    //创建列表表格
    this.SetListGrid = function (sortName, sortOrder) {
        $("#" + this.listTDID).html("<table id=\"" + ListID + "\" class=\"flexme3\"></table>");
        eval("$('#" + this.listID + "').flexigrid({ colModel: this.colModel, dataType: 'json', width: 'auto', height: 'auto', resizable: false, showToggleBtn: false, striped: true, sortname: '" + sortName + "', sortorder: '" + sortOrder + "', nonSelect: true, singleSelect: true, procmsg: '正在处理数据，请稍候……', nomsg: '没有符合条件的记录存在。', errormsg: '处理数据时出错，请与系统管理员联系！', onChangeSort: function (SortName, SortOrder) { window[\"" + this.selfObjName + "\"].sortName = SortName; window['" + this.selfObjName + "'].sortOrder = SortOrder; window['" + this.selfObjName + "'].LoadListData(); }, onError: function (XMLHttpRequest, textStatus, errorThrown) { infoDialog.OpenDialog('处理数据时出错，请与系统管理员联系！', 'Error'); } });");
        $(".flexigrid .hDiv").bind("selectstart", function () { return false; });
        if (this.resizeObjName != null && this.resizeObjName != "") {
            window[this.resizeObjName].Width();
        }
    }
    //填入列表数据
    this.FillListData = function () {
        if (JsonOriginal.Operations[this.listName].OperationData != null) {
            if (this.resizeObjName != null && this.resizeObjName != "") { window[this.resizeObjName].MinHeight(); }
            var List_Data = JsonOriginal.Operations[this.listName].OperationData;
            $("#" + this.listID).flexAddData(List_Data);
            if (this.resizeObjName != null && this.resizeObjName != "") { window[this.resizeObjName].Height(); }
            var URLP = this.UrlLisParameterst();
            $("#" + this.listID + " a.Operation").each(function (index, element) { if ($(element).attr('href').indexOf('javascript:') == -1) { $(element).attr('href', $(element).attr('href') + URLP); } });
            if (this.fillListDataComplete != null) { this.fillListDataComplete(); }
        }
    }
    //获取列表参数URL
    this.UrlLisParameterst = function () {
        var URLP = '&SearchKey=' + encodeURIComponent(this.searchKey) + '&SortName=' + encodeURIComponent(this.sortName) + '&SortOrder=' + encodeURIComponent(this.sortOrder) + '&MaxRecord=' + encodeURIComponent(this.PageSize) + '&StartRecord=' + encodeURIComponent((this.PageNum - 1) * this.PageSize);
        if (SearchTRID != null && SearchTRID != "") {
            $("#" + this.searchTRID + " .Search input[name]").each(function (index, element) {
                if ($(element).attr("name").indexOf("@") > -1) {
                    URLP += "&" + $(element).attr("name").replace(/@/ig, "") + "=" + encodeURIComponent($(element).val());
                }
            });
        }
        return URLP;
    }
    //设置列表分页
    this.SetListPage = function () {
        switch (this.pageType) {
            case "FPNL RC PNT":
                $("#" + this.pageTRID + " .Page").append("<button id=\"" + this.listID + "_FirstPage\">首页</button><button id=\"" + this.listID + "_PrevPage\">上页</button><button id=\"" + this.listID + "_NextPage\">下页</button><button id=\"" + this.listID + "_LastPage\">尾页</button><span style=\"margin-left:12px\">共有</span><span id=\"" + this.listID + "_RecordCount\"></span><span>记录</span><span style=\"margin-left:12px\">页码</span><span id=\"" + this.listID + "_PageNumText\"><span>/</span><span id=\"" + this.listID + "_PageCount\"></span>");
                break;
            case "FPNL RC PZT PNT":
                $("#" + this.pageTRID + " .Page").append("<button id=\"" + this.listID + "_FirstPage\">首页</button><button id=\"" + this.listID + "_PrevPage\">上页</button><button id=\"" + this.listID + "_NextPage\">下页</button><button id=\"" + this.listID + "_LastPage\">尾页</button><span style=\"margin-left:12px\">共有</span><span id=\"" + this.listID + "_RecordCount\"></span><span>记录</span><span style=\"margin-left:12px\">每页</span><span id=\"" + this.listID + "_PageSizeText\"></span><span>记录</span><span style=\"margin-left:12px\">页码</span><span id=\"" + this.listID + "_PageNumText\"></span><span>/</span><span id=\"" + this.listID + "_PageCount\"></span>");
                break;
            case "FPNL RC PZT PNI":
                $("#" + this.pageTRID + " .Page").append("<button id=\"" + this.listID + "_FirstPage\">首页</button><button id=\"" + this.listID + "_PrevPage\">上页</button><button id=\"" + this.listID + "_NextPage\">下页</button><button id=\"" + this.listID + "_LastPage\">尾页</button><span style=\"margin-left:12px\">共有</span><span id=\"" + this.listID + "_RecordCount\"></span><span>记录</span><span style=\"margin-left:12px\">每页</span><span id=\"" + this.listID + "_PageSizeText\"></span><span>记录</span><span style=\"margin-left:12px\">页码</span><form id=\"" + this.listID + "_PageNumForm\"><input type=\"text\" id=\"" + this.listID + "_PageNum\" style=\"width:30px;text-align:right;\" /></form><span>/</span><span id=\"" + this.listID + "_PageCount\"></span>");
                break;
            case "FPNL RC PZT PNI J":
                $("#" + this.pageTRID + " .Page").append("<button id=\"" + this.listID + "_FirstPage\">首页</button><button id=\"" + this.listID + "_PrevPage\">上页</button><button id=\"" + this.listID + "_NextPage\">下页</button><button id=\"" + this.listID + "_LastPage\">尾页</button><span style=\"margin-left:12px\">共有</span><span id=\"" + this.listID + "_RecordCount\"></span><span>记录</span><span style=\"margin-left:12px\">每页</span><span id=\"" + this.listID + "_PageSizeText\"></span><span>记录</span><span style=\"margin-left:12px\">页码</span><form id=\"" + this.listID + "_PageNumForm\"><input type=\"text\" id=\"" + this.listID + "_PageNum\" style=\"width:30px;text-align:right;\" /></form><span>/</span><span id=\"" + this.listID + "_PageCount\"></span><button id=\"" + this.listID + "_JumpPage\">跳转</button>");
                break;
            case "FPNL RC PZT PNI J F":
                $("#" + this.pageTRID + " .Page").append("<button id=\"" + this.listID + "_FirstPage\">首页</button><button id=\"" + this.listID + "_PrevPage\">上页</button><button id=\"" + this.listID + "_NextPage\">下页</button><button id=\"" + this.listID + "_LastPage\">尾页</button><span style=\"margin-left:12px\">共有</span><span id=\"" + this.listID + "_RecordCount\"></span><span>记录</span><span style=\"margin-left:12px\">每页</span><span id=\"" + this.listID + "_PageSizeText\"></span><span>记录</span><span style=\"margin-left:12px\">页码</span><form id=\"" + this.listID + "_PageNumForm\"><input type=\"text\" id=\"" + this.listID + "_PageNum\" style=\"width:30px;text-align:right;\" /></form><span>/</span><span id=\"" + this.listID + "_PageCount\"></span><button id=\"" + this.listID + "_JumpPage\">跳转</button><button id=\"" + this.listID + "_RefreshPage\">刷新</button>");
                break;
            case "FPNL RC PZS PNI J F":
                $("#" + this.pageTRID + " .Page").append("<button id=\"" + this.listID + "_FirstPage\">首页</button><button id=\"" + this.listID + "_PrevPage\">上页</button><button id=\"" + this.listID + "_NextPage\">下页</button><button id=\"" + this.listID + "_LastPage\">尾页</button><span style=\"margin-left:12px\">共有</span><span id=\"" + this.listID + "_RecordCount\"></span><span>记录</span><span style=\"margin-left:12px\">每页</span><div id=\"" + this.listID + "_PageSize\" class=\"PageSize\"><input type=\"radio\" id=\"" + this.listID + "_PageSize15\" name=\"" + this.listID + "_PageSize\" value=\"15\" /><label for=\"" + this.listID + "_PageSize15\">15</label><input type=\"radio\" id=\"" + this.listID + "_PageSize20\" name=\"" + this.listID + "_PageSize\" value=\"20\" /><label for=\"" + this.listID + "_PageSize20\">20</label><input type=\"radio\" id=\"" + this.listID + "_PageSize25\" name=\"" + this.listID + "_PageSize\" value=\"25\" /><label for=\"" + this.listID + "_PageSize25\">25</label><input type=\"radio\" id=\"" + this.listID + "_PageSize30\" name=\"" + this.listID + "_PageSize\" value=\"30\" /><label for=\"" + this.listID + "_PageSize30\">30</label></div><span>记录</span><span style=\"margin-left:12px\">页码</span><form id=\"" + this.listID + "_PageNumForm\"><input type=\"text\" id=\"" + this.listID + "_PageNum\" style=\"width:30px;text-align:right;\" /></form><span>/</span><span id=\"" + this.listID + "_PageCount\"></span><button id=\"" + this.listID + "_JumpPage\">跳转</button><button id=\"" + this.listID + "_RefreshPage\">刷新</button>");
                break;
            default:
                $("#" + this.pageTRID + " .Page").append("<button id=\"" + this.listID + "_FirstPage\">首页</button><button id=\"" + this.listID + "_PrevPage\">上页</button><button id=\"" + this.listID + "_NextPage\">下页</button><button id=\"" + this.listID + "_LastPage\">尾页</button><span style=\"margin-left:12px\">共有</span><span id=\"" + this.listID + "_RecordCount\"></span><span>记录</span><span style=\"margin-left:12px\">每页</span><div id=\"" + this.listID + "_PageSize\" class=\"PageSize\"><input type=\"radio\" id=\"" + this.listID + "_PageSize15\" name=\"" + this.listID + "_PageSize\" value=\"15\" /><label for=\"" + this.listID + "_PageSize15\">15</label><input type=\"radio\" id=\"" + this.listID + "_PageSize20\" name=\"" + this.listID + "_PageSize\" value=\"20\" /><label for=\"" + this.listID + "_PageSize20\">20</label><input type=\"radio\" id=\"" + this.listID + "_PageSize25\" name=\"" + this.listID + "_PageSize\" value=\"25\" /><label for=\"" + this.listID + "_PageSize25\">25</label><input type=\"radio\" id=\"" + this.listID + "_PageSize30\" name=\"" + this.listID + "_PageSize\" value=\"30\" /><label for=\"" + this.listID + "_PageSize30\">30</label></div><span>记录</span><span style=\"margin-left:12px\">页码</span><form id=\"" + this.listID + "_PageNumForm\"><input type=\"text\" id=\"" + this.listID + "_PageNum\" style=\"width:30px;text-align:right;\" /></form><span>/</span><span id=\"" + this.listID + "_PageCount\"></span><button id=\"" + this.listID + "_JumpPage\">跳转</button><button id=\"" + this.listID + "_RefreshPage\">刷新</button>");
        }
        if (this.listName != null && this.listName != "") {
            this.PageSize = JsonOriginal.Operations[this.listName].MaxRecord;
            this.RecordCount = JsonOriginal.Operations[this.listName].RecordCount;
            this.PageNum = JsonOriginal.Operations[this.listName].StartRecord / this.PageSize + 1;
        } else {
            this.PageSize = 0;
            this.RecordCount = 0;
            this.PageNum = 0;
        }
        $("#" + this.listID + "_PageSize" + this.PageSize).attr("checked", "checked");
        $("#" + this.listID + "_PageSize").buttonset();
        eval("$(\"#" + this.listID + "_PageSize15\").change(function () { if (window[\"" + this.selfObjName + "\"].PageSize != 15) { window[\"" + this.selfObjName + "\"].PageSize = 15; window[\"" + this.selfObjName + "\"].PageNum = 1; window[\"" + this.selfObjName + "\"].LoadListData(); } });");
        eval("$(\"#" + this.listID + "_PageSize20\").change(function () { if (window[\"" + this.selfObjName + "\"].PageSize != 20) { window[\"" + this.selfObjName + "\"].PageSize = 20; window[\"" + this.selfObjName + "\"].PageNum = 1; window[\"" + this.selfObjName + "\"].LoadListData(); } });");
        eval("$(\"#" + this.listID + "_PageSize25\").change(function () { if (window[\"" + this.selfObjName + "\"].PageSize != 25) { window[\"" + this.selfObjName + "\"].PageSize = 25; window[\"" + this.selfObjName + "\"].PageNum = 1; window[\"" + this.selfObjName + "\"].LoadListData(); } });");
        eval("$(\"#" + this.listID + "_PageSize30\").change(function () { if (window[\"" + this.selfObjName + "\"].PageSize != 30) { window[\"" + this.selfObjName + "\"].PageSize = 30; window[\"" + this.selfObjName + "\"].PageNum = 1; window[\"" + this.selfObjName + "\"].LoadListData(); } });");
    }
    //计算分页参数
    this.MathListPage = function () {
        if (this.listName != null && this.listName != "" && this.PageSize > 0) {
            this.PageCount = Math.floor((this.RecordCount + this.PageSize - 1) / this.PageSize);
        } else {
            this.PageCount = 0;
        }
        $("#" + this.listID + "_PageSize" + this.PageSize).attr("checked", "checked");
        $("#" + this.listID + "_PageSize").buttonset();
        $("#" + this.listID + "_PageSizeText").html(this.PageSize);
        $("#" + this.listID + "_SearchKey").val(this.searchKey);
        $("#" + this.listID + "_PageNum").val(this.PageNum);
        $("#" + this.listID + "_PageNumText").html(this.PageNum);
        $("#" + this.listID + "_PageCount").html(this.PageCount);
        $("#" + this.listID + "_RecordCount").html(this.RecordCount);
        $("#" + this.listID + "_PageSize").buttonset({ disabled: (this.PageCount == 0) });
        $("#" + this.listID + "_JumpPage").button({ disabled: (this.PageCount == 0) });
        $("#" + this.listID + "_FirstPage").button({ disabled: (this.PageNum == 1 || this.PageCount == 0) });
        $("#" + this.listID + "_PrevPage").button({ disabled: (this.PageNum == 1 || this.PageCount == 0) });
        $("#" + this.listID + "_LastPage").button({ disabled: (this.PageNum == this.PageCount || this.PageCount == 0) });
        $("#" + this.listID + "_NextPage").button({ disabled: (this.PageNum == this.PageCount || this.PageCount == 0) });
    }
    //设置按钮事件
    this.SetListButtons = function () {
        var ButtonText = "";
        if (this.iconButton) {
            ButtonText = ",text: false";
        }
        eval("$(\"#" + this.listID + "_FirstPage\").button({ icons: { primary: \"ui-icon-seek-first\"}" + ButtonText + " }).click(function () { window[\"" + this.selfObjName + "\"].PageNum = 1; window[\"" + this.selfObjName + "\"].LoadListData(); });");
        eval("$(\"#" + this.listID + "_PrevPage\").button({ icons: { primary: \"ui-icon-seek-prev\"}" + ButtonText + " }).click(function () { window[\"" + this.selfObjName + "\"].PageNum = window[\"" + this.selfObjName + "\"].PageNum - 1; window[\"" + this.selfObjName + "\"].LoadListData(); });");
        eval("$(\"#" + this.listID + "_NextPage\").button({ icons: { secondary: \"ui-icon-seek-next\"}" + ButtonText + " }).click(function () { window[\"" + this.selfObjName + "\"].PageNum = window[\"" + this.selfObjName + "\"].PageNum + 1; window[\"" + this.selfObjName + "\"].LoadListData(); });");
        eval("$(\"#" + this.listID + "_LastPage\").button({ icons: { secondary: \"ui-icon-seek-end\"}" + ButtonText + " }).click(function () { window[\"" + this.selfObjName + "\"].PageNum = window[\"" + this.selfObjName + "\"].PageCount; window[\"" + this.selfObjName + "\"].LoadListData(); });");
        eval("$(\"#" + this.listID + "_JumpPage\").button({ icons: { primary: \"ui-icon-arrowreturnthick-1-n\"}" + ButtonText + " }).click(function () { if(parseInt($(\"#" + this.listID + "_PageNum\").val()) > 0 && parseInt($(\"#" + this.listID + "_PageNum\").val()) <= window[\"" + this.selfObjName + "\"].PageCount) { window[\"" + this.selfObjName + "\"].PageNum = parseInt($(\"#" + this.listID + "_PageNum\").val()); window[\"" + this.selfObjName + "\"].LoadListData(); } else { infoDialog.OpenDialog('页码必须大于 0 少于 ' +  window[\"" + this.selfObjName + "\"].PageCount + '！', 'Alert'); } });");
        eval("$(\"#" + this.listID + "_RefreshPage\").button({ icons: { primary: \"ui-icon-refresh\"}" + ButtonText + " }).click(function () { window[\"" + this.selfObjName + "\"].LoadListData(); });");
        eval("$(\"#" + this.listID + "_PageNumForm\").submit(function () { if(parseInt($(\"#" + this.listID + "_PageNum\").val()) > 0 && parseInt($(\"#" + this.listID + "_PageNum\").val()) <= window[\"" + this.selfObjName + "\"].PageCount) { window[\"" + this.selfObjName + "\"].PageNum = $(\"#" + this.listID + "_PageNum\").val(); window[\"" + this.selfObjName + "\"].LoadListData(); return false; } else { infoDialog.OpenDialog('页码必须大于 0 少于 ' +  window[\"" + this.selfObjName + "\"].PageCount + '！', 'Alert'); return false; } });");
        eval("$(\"#" + this.listID + "_SearchButton\").button({ icons: { primary: \"ui-icon-search\"}" + ButtonText + " }).click(function () { window[\"" + this.selfObjName + "\"].searchKey = $(\"#" + this.listID + "_SearchKey\").val(); window['" + this.selfObjName + "'].PageNum = 1; window[\"" + this.selfObjName + "\"].LoadListData(); });");
        eval("$(\"#" + this.listID + "_SearchKeyForm\").submit(function () { window[\"" + this.selfObjName + "\"].searchKey = $(\"#" + this.listID + "_SearchKey\").val(); window['" + this.selfObjName + "'].PageNum = 1; window[\"" + this.selfObjName + "\"].LoadListData(); return false; });");
    }  
    //获取输出参数
    this.GetParameters = function () {
        var Parameters = { "@SortName": this.sortName, "@SortOrder": this.sortOrder, "@SearchKey": this.searchKey };
        $("#" + this.searchTRID + " .Search input[name]").each(function (index, element) {
            Parameters[$(element).attr("name")] = $(element).val();
        });
        return Parameters;
    }
    //设置列表搜索
    this.SetListSearch = function () {
        $("#" + this.searchTRID + " .Search").append("<form id=\"" + this.listID + "_SearchKeyForm\"><input type=\"text\" id=\"" + this.listID + "_SearchKey\" value=\"" + this.searchKey + "\" style=\"width:100px;\" /></form><button id=\"" + this.listID + "_SearchButton\" >搜索</button>");
    }
    //读取数据操作
    this.LoadListData = function () {
        var JsonSend = { "ActionParameters": JSON.stringify([[{ "OperationKey": this.listName, "Parameters": this.GetParameters(), "JsonParameter": "{\"记录控制\":[{\"开始记录\":" + ((this.PageNum - 1) * this.PageSize) + ",\"返回数量\":" + this.PageSize + "}]}"}]]) };
        window.ajaxClass.AjaxSubmit(JsonOriginal.UrlAction, JsonSend, "", "window." + this.selfObjName + ".SetLoadData('" + this.selfObjName + "',data);", "window." + this.selfObjName + ".SetLoadDataError();", false, true);
    }
    //外部数据读取
    this.LoadData = function (FirstSuccessCode, LastSuccessCode, ErrorCode, JsonParameter, ActionParameters) {
        var APs = [[{ "OperationKey": this.listName, "Parameters": this.GetParameters(), "JsonParameter": JsonParameter}]];
        if (ActionParameters != null && ActionParameters != undefined) {
            for (var i = 0; i < ActionParameters.length; i++) {
                APs.push(ActionParameters[i]);
            }
        }
        var JsonSend = { "ActionParameters": JSON.stringify(APs) };
        window.ajaxClass.AjaxSubmit(JsonOriginal.UrlAction, JsonSend, "", FirstSuccessCode + "window." + this.selfObjName + ".SetLoadData('" + this.selfObjName + "',data); " + LastSuccessCode, "window." + this.selfObjName + ".SetLoadDataError();" + ErrorCode, false, true);
    }
    //处理读取数据
    this.SetLoadData = function (SelfObjName, data) {
        JsonOriginal.Operations[window[SelfObjName].listName].OperationData = data.ReturnData[0];
        window[SelfObjName].PageNum = data.ReturnData[0].page;
        window[SelfObjName].RecordCount = data.ReturnData[0].total;
        window[SelfObjName].PageSize = data.ReturnData[0].MaxRecord;
        window[SelfObjName].FillListData();
        window[SelfObjName].MathListPage();
    }
    //读取数据出错处理
    this.SetLoadDataError = function () {
        JsonOriginal.Operations[window[SelfObjName].listName].OperationData = { "page": 0, "total": 0, "rows": [] };
        window[SelfObjName].PageNum = 0;
        window[SelfObjName].RecordCount = 0;
        window[SelfObjName].PageSize = 0;
        window[SelfObjName].FillListData();
        window[SelfObjName].MathListPage();
    }
    //外部调用刷新
    this.Refresh = function (DateList, SortName, SortOrder, SearchKey) {      
        this.sortName = SortName;
        this.sortOrder = SortOrder;
        this.searchKey = SearchKey;
        eval("JsonOriginal.Operations[\"" + this.listName + "\"].OperationData=DateList; window." + this.selfObjName + ".PageNum=DateList.page; window." + this.selfObjName + ".RecordCount=DateList.total; window." + this.selfObjName + ".PageSize=DateList.MaxRecord; window." + this.selfObjName + ".FillListData(); window." + this.selfObjName + ".MathListPage();");
    }
    //初始化
    if (SortName != null) { this.SetListGrid(this.sortName, this.sortOrder); }
    if (PageTRID != null && PageTRID != "") { this.SetListPage(); this.MathListPage(); }
    if (SearchTRID != null && SearchTRID != "") { this.SetListSearch(); }
    this.SetListButtons();
    if (ListName != null && ListName != "") { this.FillListData(); }
}

/* --------------------------------------------------------------------------------------------------- */

function DateControl(SelfObjName, DateContorls) { 
    this.selfObjName = SelfObjName;
    this.dateContorls = DateContorls;

    this.SetDateControl = function () {
        for (var i = 0; i < this.dateContorls.length; i++) {
            $(this.dateContorls[i].Selecter).datepicker({
                showOtherMonths: true,
                selectOtherMonths: true,
                dateFormat: 'yy-mm-dd',
                changeMonth: true,
                changeYear: true,
                defaultDate: 0
            });
            if (this.dateContorls[i].DefaultDate != undefined && this.dateContorls[i].DefaultDate != null && this.dateContorls[i].DefaultDate != '') {
                $(this.dateContorls[i].Selecter).val(this.dateContorls[i].DefaultDate.pattern("yyyy-MM-dd"));
            }
        }
    }

    this.CheckDateControl = function (Selecter) {
        if ($(Selecter).val() != "") {
            if (!IsValidDate($(Selecter).val())) {
                eval("infoDialog.OpenDialog('日期格式错误，日期格式：年年年年-月月-日日，请注意闰年！', 'Error', null, function () { $('#" + $(Selecter).attr("id") + "').focus(); });");
                return false;
            } else {
                $(Selecter).val(StringToDate($(Selecter).val()).pattern("yyyy-MM-dd"));
            }
        }
        return true;
    }
    if (DateContorls != undefined && DateContorls != null) {
        this.SetDateControl();
    }
}

/* --------------------------------------------------------------------------------------------------- */

function AutoComplete() {
    this.SetAutoComplete = function (Selecter, Position, MaxHeight, MaxWidth, MinWidth, SelectAutoComplete, SelfObjName, Parameters, index, EmptyObj) {
        $(Selecter).autocomplete({
            minLength: 2,
            delay: 600,
            position: Position,
            source: function (event, ui) {
                window[SelfObjName].AjaxAutoComplete(this.element[0].lang, event, ui, Parameters);
            },
            select: function (event, ui) {
                window[SelfObjName][event.target.id] = null;
                event.target.blur();
                if (index != undefined) {
                    SelectAutoComplete(event, ui, index);
                } else {
                    SelectAutoComplete(event, ui);
                }
                if (EmptyObj) {
                    setTimeout("$('" + Selecter + "').val('');", 200);
                }
            }
        });
        $("ul.ui-autocomplete.ui-menu.ui-widget.ui-widget-content.ui-corner-all").css("max-height", MaxHeight).css("max-width", MaxWidth).css("min-width", MinWidth).css("overflow-y", "auto");
    }
    this.SetAutoCompletes = function (AutoCompletes, SelfObjName) {
        var Selecter;
        var Parameters = {};
        for (i = 0; i < AutoCompletes.length; i++) {
            Selecter = "#" + AutoCompletes[i].ObjID[0];
            for (j = 1; j < AutoCompletes[i].ObjID.length; j++) {
                Selecter += ",#" + AutoCompletes[i].ObjID[j];
            }
            for (j in AutoCompletes[i].Parameters) {
                Parameters[j] = $("#" + AutoCompletes[i].Parameters[j]).val();
            }
            if (AutoCompletes[i].SelectAutoComplete != undefined) {
                if (AutoCompletes[i].PositionPanel != undefined) {
                    this.SetAutoComplete(Selecter, { my: "left top", at: "left bottom", of: "#" + AutoCompletes[i].DropDownPosition, collision: "none" }, "264px", AutoCompletes[i].DropDownWidth + "px", AutoCompletes[i].DropDownWidth + "px", function (event, ui, i) { AutoCompletes[i].SelectAutoComplete(event, ui, AutoCompletes[i].FillTo); if ($("#" + AutoCompletes[i].PositionPanel + " tr").size() >= AutoCompletes[i].PositionDownNum) { $(Selecter).autocomplete("option", "position", { my: "left bottom", at: "left top", of: "#" + AutoCompletes[i].DropDownPosition, collision: "none" }); } else { $(Selecter).autocomplete("option", "position", { my: "left top", at: "left bottom", of: "#" + AutoCompletes[i].DropDownPosition, collision: "none" }); } }, SelfObjName, Parameters, i, AutoCompletes[i].EmptyObj);
                } else {
                    this.SetAutoComplete(Selecter, { my: "left top", at: "left bottom", of: "#" + AutoCompletes[i].DropDownPosition, collision: "none" }, "264px", AutoCompletes[i].DropDownWidth + "px", AutoCompletes[i].DropDownWidth + "px", function (event, ui, i) { AutoCompletes[i].SelectAutoComplete(event, ui, AutoCompletes[i].FillTo); }, SelfObjName, Parameters, 0, AutoCompletes[i].EmptyObj);
                }
            } else {
                this.SetAutoComplete(Selecter, { my: 'left top', at: 'left bottom', of: '#' + AutoCompletes[i].DropDownPosition, collision: 'none' }, '264px', AutoCompletes[i].DropDownWidth + 'px', AutoCompletes[i].DropDownWidth + 'px', function (event, ui, i) { var Values = ui.item.label.substring(1, ui.item.label.length - 1).split('], ['); for (var j = 0; (j < AutoCompletes[i].FillTo.length && j < Values.length); j++) { $('#' + AutoCompletes[i].FillTo[j]).val(Values[j]); } }, SelfObjName, Parameters, i, AutoCompletes[i].EmptyObj);
            }
            if (AutoCompletes[i].AutoLinkChange) {
                this.AutoLinkChange(Selecter, SelfObjName);
            }
        }
    }
    this.AjaxAutoComplete = function (OperationKey, request, response, Parameters) {
        if (Parameters != undefined && Parameters != null) {
            Parameters["@Key"] = request.term;
        } else {
            Parameters = { "@Key": request.term };
        }
        $.ajax({
            url: JsonOriginal.UrlAction,
            type: "POST",
            dataType: "json",
            data: { "ActionParameters": JSON.stringify([[{ "OperationKey": OperationKey, "Parameters": Parameters}]]) },
            success: function (data) {
                response(data.ReturnData[0]);
            }
        });
    }      
    this.AutoLinkChange = function (Selecter, SelfObjName) {
        $(Selecter).focus(function () {
            window[SelfObjName][this.id] = $(this).val();
        });
        $(Selecter).blur(function () { setTimeout("if (window." + SelfObjName + "['" + this.id + "'] != null) { $('#" + this.id + "').val(window." + SelfObjName + "['" + this.id + "']); }", 200); });
    }
}   

/* --------------------------------------------------------------------------------------------------- */

function ShowHidden() {
    this.ShowHidden = function (DataObj) {
        for (var i = 0; i < DataObj.Show.length; i++) {
            switch ($("#" + DataObj.Show[i]).attr("tagName")) {
                case "td":
                    $("#" + DataObj.Show[i]).css("display", "block");
                    $("#" + DataObj.Show[i]).removeAttr("style");
                    break;
                default:
                    $("#" + DataObj.Show[i]).css("display", "block");
                    break;
            }
        }
        for (var i = 0; i < DataObj.Hidden.length; i++) {
            $("#" + DataObj.Hidden[i]).css("display", "none");
        }
    }
}

/* --------------------------------------------------------------------------------------------------- */

function Comment(PanelID, SelfObjName) {
    this.selfObjName = SelfObjName;
    this.panelID = PanelID;
    //显示评论列表
    this.AddComment = function (Items) {
        $("#" + this.panelID + " .CommentDiv, #" + this.panelID + " .DetailLine").remove();
        if (Items != null && $("#" + this.panelID + " .Panel").size() == 1) {
            for (var i = 0; i < Items.length; i++) {
                $("#" + this.panelID + " .Panel:last").before("<div class=\"CommentDiv\">" + $("#CommentHTML").html() + "</div><div class=\"DetailLine\" style=\"margin:4px -4px 0 0;background-color:#CFE5E5;height:1px;\"><span></span></div>");
                $("#" + this.panelID + " .CommentDiv:last").find("input[name=CommentAutoID]").val(Items[i]["AutoID"]);
                $("#" + this.panelID + " .CommentDiv:last").find("input[name=CommentUserID]").val(Items[i]["UserID"]);
                $("#" + this.panelID + " .CommentDiv:last").find("input[name=CommentUsername]").val(Items[i]["person"]);
                $("#" + this.panelID + " .CommentDiv:last").find("input[name=CommentDateTime]").val(Items[i]["create_date"]);
                $("#" + this.panelID + " .CommentDiv:last").find(".CommentText").html(Items[i]["doc_txt"]);
                var selfObjName = this.selfObjName;
                $("#" + this.panelID + " .CommentDiv:last").find(".AIcon .Icon").click(function () {
                    var AutoID = $(this).parent().parent().find("input[name=CommentAutoID]").val();
                    infoDialog.OpenDialog('你确认删除该评论？', 'Alert', function () {
                        var ActionParameters = [[{ "OperationKey": "删除评论", "Parameters": { "@AutoID": AutoID}}], [{ "OperationKey": "获取评论"}]];
                        var JsonSend = { "ActionParameters": JSON.stringify(ActionParameters) };
                        window.ajaxClass.AjaxSubmit(JsonOriginal.UrlAction, JsonSend, "", "if(data.ReturnData[1]!=null){$('label[for=radio3] span').html('相关评论（'+ data.ReturnData[1].length +'）');}else{$('label[for=radio3] span').html('相关评论（0）');} window." + selfObjName + ".AddComment(data.ReturnData[1]);window.editor.setData('');", "", true, true);
                    });
                });
                if (Items[i]["UserID"] == JsonOriginal.UserID || JsonOriginal.UserID == "Administrator") {
                    $("#" + this.panelID + " .CommentDiv:last").find(".AIcon").css("display", "block");
                }
            }
        }
    }
    //设置评论
    this.SetComment = function (EndCode) {
        if (window.editor == undefined) {
            this.AddComment(JsonOriginal.Operations["获取评论"].OperationData);
            window.editor = CKEDITOR.replace("CommentText", {
                removePlugins: 'resize',
                toolbar: 'MinToolbar',
                height: 120,
                width: 845
            });
            var panelID = this.panelID;
            var selfObjName = this.selfObjName;
            CKEDITOR.instances["CommentText"].on("instanceReady", function () {
                $("#" + panelID + " .cke_button__save").removeClass("cke_button_disabled").addClass("cke_button_off");
                $("#" + panelID + " .cke_button__save").click(function () {
                    if (window.editor.getData() == "") {
                        infoDialog.OpenDialog('评论内容不能为空！', 'Error');
                    } else {
                        var ActionParameters = [[{ "OperationKey": "添加评论", "Parameters": { "@doc_txt": window.editor.getData()}}], [{ "OperationKey": "获取评论"}]];
                        var JsonSend = { "ActionParameters": JSON.stringify(ActionParameters) };
                        window.ajaxClass.AjaxSubmit(JsonOriginal.UrlAction, JsonSend, "", "$('label[for=radio3] span').html('相关评论（'+ data.ReturnData[1].length +'）');window." + selfObjName + ".AddComment(data.ReturnData[1]);window.editor.setData('');", "", true, true);
                    }
                });
            });
            $("#" + this.panelID + " .Panel:last").css("display", "block");
        } else if (window.ReadOnly) {
            $("#" + this.panelID + " .DetailLine:last").css("display", "none");
        }
        eval(EndCode);
    }
    //添加评论操作
    this.SetCommentActionObj = function (TempJson) {
        if (window.editor != undefined) {
            if (window.editor.getData() != "") {
                TempJson.push([{ "OperationKey": "添加评论", "Parameters": { "@doc_txt": window.editor.getData()}}]);
            }
        }
    }
}

/* --------------------------------------------------------------------------------------------------- */

function AutoMath() {
    this.MathIt = function (PanelObj, MathStr) {
        Formula = MathStr.split(" ");
        for (j = 0; j < Formula.length; j++) {
            if (Formula[j] != "*" && Formula[j] != "/" && Formula[j] != "+" && Formula[j] != "-" && Formula[j] != "=" && Formula[j] != "<" && Formula[j] != ">" && Formula[j] != "!=" && Formula[j] != "<=" && Formula[j] != ">=") {
                if (PanelObj.find("td[abbr='" + Formula[j] + "'] div input").size() > 0) {
                    Formula[j] = PanelObj.find("td[abbr='" + Formula[j] + "'] div input").val();
                } else {
                    Formula[j] = PanelObj.find("td[abbr='" + Formula[j] + "'] div").text();
                }
            }
        }
        FormulasEval = "";
        for (j = 0; j < Formula.length; j++) {
            if (Formula[j] != "") {
                FormulasEval += Formula[j];
            } else {
                FormulasEval = "";
                break;
            }
        }
        if (FormulasEval != "") {
            FormulasEval = eval(FormulasEval);
            return FormulasEval;
        } else {
            return null;
        }
    }

    this.AutoMath = function (EventObj, MathData) {
        var TR = $(EventObj).parent().parent().parent();
        var Formulas;
        var FormulasEval;
        for (var i = 0; i < MathData.length; i++) {
            switch (MathData[i].Type) {
                case "Row":
                    if (MathData[i].Compare != undefined) {
                        FormulasEval = this.MathIt(TR, MathData[i].Compare);
                        if (FormulasEval != null) {
                            if (!FormulasEval) {
                                infoDialog.OpenDialog(MathData[i].ErrorText, 'Error', null, function () { $(EventObj).focus(); });
                            }
                        }
                    }
                    FormulasEval = this.MathIt(TR, MathData[i].Formula);
                    if (FormulasEval != null) {
                        if (TR.find("td[abbr='" + MathData[i].Value + "'] div input").size() > 0) {
                            TR.find("td[abbr='" + MathData[i].Value + "'] div input").val(FormulasEval.toFixed(MathData[i].FixLength));
                        } else {
                            TR.find("td[abbr='" + MathData[i].Value + "'] div").text(FormulasEval.toFixed(MathData[i].FixLength));
                        }
                    } else {
                        if (TR.find("td[abbr='" + MathData[i].Value + "'] div input").size() > 0) {
                            TR.find("td[abbr='" + MathData[i].Value + "'] div input").val("");
                        } else {
                            TR.find("td[abbr='" + MathData[i].Value + "'] div").text("");
                        }
                    }
                    break;
                case "ColSum":
                    Formulas = 0;
                    $("#" + MathData[i].ListID + " tr td[abbr='" + MathData[i].ColName + "'] div").each(function (index, element) {
                        if ($(element).is("input")) {
                            if ($(element).find("input").val() != "") {
                                Formulas += parseFloat($(element).find("input").val());
                            }
                        } else {
                            if ($(element).text() != "") {
                                Formulas += parseFloat($(element).text());
                            }
                        }
                    });
                    $("#" + MathData[i].Value).text(Formulas.toFixed(MathData[i].FixLength));
                    break;
            }
        }
    }
}

/* --------------------------------------------------------------------------------------------------- */

function UpLoadFile(SelfObjName, UploadDocPanelID, FileSizeLimit, FileDivID, FileHtmlID, UpPermissionName, EditPermissionName, DeletePermissionName, DownPermissionName, ActionGetKey, ActionUpKey, ActionEditKey, ActionDelKey, ActionDownKey, Loaddata, ShowPanelEval, ErrorPanelEval) {
    this.selfObjName = SelfObjName;
    this.uploadDocPanelID = UploadDocPanelID;
    this.fileSizeLimit = FileSizeLimit;
    this.fileDivID = FileDivID;
    this.fileHtmlID = FileHtmlID;
    this.upPermissionName = UpPermissionName;
    this.editPermissionName = EditPermissionName;
    this.downPermissionName = DownPermissionName;
    this.deletePermissionName = DeletePermissionName;   
    this.actionGetKey = ActionGetKey;
    this.actionUpKey = ActionUpKey;
    this.actionDelKey = ActionDelKey;
    this.actionEditKey = ActionEditKey;
    this.actionDownKey = ActionDownKey;
    this.loaddata = Loaddata;
    this.showPanelEval = ShowPanelEval;
    this.errorPanelEval = ErrorPanelEval;

    this.SetFileUpdate = function (UpLoad) {
        if (window.activityFile == null) {
            if (HasPermission(this.upPermissionName) && UpLoad) {
                var JsonObj = JSON.parse(JsonOriginal.Operations[this.actionUpKey].JsonParameter);
                eval("window.uploadifyClass = new UploadifyClass(\"DocUpload\", JsonOriginal.UrlUploadify, \"上传文档\", \"文档文件\", JsonObj[\"文件后序\"], this.fileSizeLimit, { \"ActionParameters\": JSON.stringify([[{ \"OperationKey\": this.actionUpKey}]]) }, function (file, data, response) { eval(\"window."+ this.selfObjName +".FileUploadSuccess(file, data, response);\"); }); ");
                $("#" + this.uploadDocPanelID).css("display","block").removeAttr("style");
            }
            if (this.loaddata) {
                var JsonSend = { "ActionParameters": JSON.stringify([[{ "OperationKey": this.actionGetKey}]]) };
                window.ajaxClass.AjaxSubmit(JsonOriginal.UrlAction, JsonSend, "", "window.activityFile = new ActivityItem(\"activityFile\", \"#" + this.fileHtmlID + "\", null, \"" + this.fileDivID + "\", \"<div class=\\\"FileDiv\\\">\", \"</div>\", null, null, false);window." + this.selfObjName + ".SetFiles(data.ReturnData[0]);" + this.showPanelEval, this.errorPanelEval, false, true);
            } else {
                window.activityFile = new ActivityItem("activityFile", "#" + this.fileHtmlID, null, this.fileDivID, "<div class=\"FileDiv\">", "</div>", null, null, false);
                this.SetFiles(JsonOriginal.Operations[this.actionGetKey].OperationData);
                eval(this.showPanelEval);
            }
        } else {
            eval(this.showPanelEval);
        }
    }
    this.SetFileActionObj = function (TempJson) {
        var DelKey = this.actionDelKey;
        var EditKey = this.actionEditKey;
        $("#" + this.fileDivID + " .FileDiv").each(function (index, element) {
            if ($(element).hasClass("DeleteFileDiv")) {
                TempJson.push([{ "OperationKey": DelKey, "JsonParameter": JSON.stringify({ "内部标识": $(element).find("input[name='ItemType']").val() })}]);
            } else if ($(element).find("input[name='ItemName']").val() != $(element).find("input[name='ItemName']").attr("title") || ($(element).find("input[name='ItemEnable']").is(':checked') != ($(element).find("input[name='ItemType']").val().indexOf("^OL") > -1))) {
                TempJson.push([{ "OperationKey": EditKey, "JsonParameter": JSON.stringify({ "内部标识": $(element).find("input[name='ItemType']").val(), "文件名称": $(element).find("input[name='ItemName']").val(), "外部下载": $(element).find("input[name='ItemEnable']").is(':checked') })}]);
            }
        });
    }
    this.DelFileActionObj = function (TempJson) {
        var DelKey = this.actionDelKey;
        if ($("#" + this.fileDivID + " .FileDiv").size() > 0) {
            $("#" + this.fileDivID + " .FileDiv").each(function (index, element) {
                TempJson.push([{ "OperationKey": DelKey, "JsonParameter": JSON.stringify({ "内部标识": $(element).find("input[name='ItemType']").val() })}]);
            });
        } else if (JsonOriginal.Operations[this.actionGetKey].OperationData != null) {
            for (var i = 0; i < JsonOriginal.Operations[this.actionGetKey].OperationData.length; i++) {
                TempJson.push([{ "OperationKey": DelKey, "JsonParameter": JSON.stringify({ "内部标识": JsonOriginal.Operations[this.actionGetKey].OperationData[i] })}]);
            } 
        }
    }
    this.SetFiles = function (Data) {
        $("#" + this.fileDivID).html("");
        if (Data != null) {
            for (var i = 0; i < Data.length; i++) {
                Filename = Data[i].substr(Data[i].indexOf("-") + 1, Data[i].lastIndexOf(".") - Data[i].indexOf("-") - 1);
                this.AddFile(Data[i], Filename, (Data[i].indexOf("^OL") > -1));
            }
            if (HasntPermission(this.deletePermissionName)) { $("#" + this.fileDivID + " .DeleteFile").css("visibility", "hidden"); }
            if (HasntPermission(this.editPermissionName)) { $("#" + this.fileDivID + " input[type=checkbox]").attr("disabled", "disabled"); $("#" + this.fileDivID + " input").removeClass("Required").attr("readonly", "readonly"); }
        }
    }
    this.AddFile = function (ItemType, ItemName, ItemEnable) {
        UPDT = ItemType.substr(ItemType.indexOf("_") + 1, 15);
        UPDT = "20" + UPDT.substr(0, 1) + UPDT.substr(1, 1) + "-" + UPDT.substr(2, 1) + UPDT.substr(3, 1) + "-" + UPDT.substr(4, 1) + UPDT.substr(5, 1) + " " + UPDT.substr(6, 1) + UPDT.substr(7, 1) + ":" + UPDT.substr(8, 1) + UPDT.substr(9, 1) + ":" + UPDT.substr(10, 1) + UPDT.substr(11, 1) + "." + UPDT.substr(12, 1) + UPDT.substr(13, 1) + UPDT.substr(14, 1);
        var DownUrl = JsonOriginal.UrlDown + "&";
        if (ItemType.indexOf("^OL") > 0)
            DownUrl = JsonOriginal.UrlDown.substr(0, DownUrl.lastIndexOf("?") + 1);
        window.activityFile.AddItem();
        $("#" + this.fileDivID + " div.FileDiv:last").find("input[name='ItemType']").val(ItemType);
        $("#" + this.fileDivID + " div.FileDiv:last").find("input[name='ItemTime']").val(UPDT);
        $("#" + this.fileDivID + " div.FileDiv:last").find("input[name='ItemTime']").attr("title", UPDT);
        $("#" + this.fileDivID + " div.FileDiv:last").find("input[name='ItemName']").val(ItemName);
        $("#" + this.fileDivID + " div.FileDiv:last").find("input[name='ItemName']").attr("title", ItemName);
        $("#" + this.fileDivID + " div.FileDiv:last").find(".DownLoad a").attr("title", "下载文件 " + ItemName + ItemType.substring(ItemType.indexOf(".")));
        if (HasntPermission(this.downPermissionName) && ItemType.indexOf("^OL") == -1) {
            $("#" + this.fileDivID + " div.FileDiv:last").find(".DownLoad").css("visibility", "hidden");
        } else {
            $("#" + this.fileDivID + " div.FileDiv:last").find(".DownLoad a").attr("href", DownUrl + "FileName=" + encodeURIComponent(ItemType) + "&OperationKey=" + encodeURIComponent(this.actionDownKey));
        }
        if (HasntPermission(this.deletePermissionName)) {
            $("#" + this.fileDivID + " div.FileDiv:last").find(".DeleteFile").css("visibility", "hidden");
        }
        if (ItemEnable) {
            $("#" + this.fileDivID + " div.FileDiv:last").find("input[name='ItemEnable']").attr("checked", "checked");
        }
    }
    this.FileUploadSuccess = function (file, data, response) {
        var Filename = file.name.substr(0, file.name.lastIndexOf("."));   
        this.AddFile(data, Filename, false);
    }
    this.DeleteFile = function DeleteFile(EventObj) {
        var selfObjName = this.selfObjName;
        var value = $(EventObj).parent().parent().find("input[name='ItemType']").val();
        var actionDelKey = this.actionDelKey;
        infoDialog.OpenDialog('你确认删除该文件？', 'Alert', function () {
            var ActionParameters = [[{ "OperationKey": actionDelKey, "JsonParameter": JSON.stringify({ "内部标识": value })}], [{ "OperationKey": "获取文档"}]];
            var JsonSend = { "ActionParameters": JSON.stringify(ActionParameters) };
            window.ajaxClass.AjaxSubmit(JsonOriginal.UrlAction, JsonSend, "", "if(data.ReturnData[1]!=null){$('label[for=radio4] span').html('相关文档（'+ data.ReturnData[1].length +'）');}else{$('label[for=radio3] span').html('相关评论（0）');} window." + selfObjName + ".SetFiles(data.ReturnData[1]);", "", true, true);
        });
    } 
}

/* --------------------------------------------------------------------------------------------------- */
/**       
* 对Date的扩展，将 Date 转化为指定格式的String       
* 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 个占位符       
* 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)       
* eg:       
* (new Date()).pattern("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423       
* (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04       
* (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04       
* (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04       
* (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18       
*/
Date.prototype.pattern = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份           
        "d+": this.getDate(), //日           
        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时           
        "H+": this.getHours(), //小时           
        "m+": this.getMinutes(), //分           
        "s+": this.getSeconds(), //秒           
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度           
        "S": this.getMilliseconds() //毫秒           
    };
    var week = {
        "0": "/u65e5",
        "1": "/u4e00",
        "2": "/u4e8c",
        "3": "/u4e09",
        "4": "/u56db",
        "5": "/u4e94",
        "6": "/u516d"
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    if (/(E+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}    
/* --------------------------------------------------------------------------------------------------- */
//+---------------------------------------------------  
//| 字符串转成日期类型   
//| 格式 MM/dd/YYYY MM-dd-YYYY YYYY/MM/dd YYYY-MM-dd  
//+---------------------------------------------------  
function StringToDate(DateStr) {
    var converted = Date.parse(DateStr);
    var myDate = new Date(converted);
    if (isNaN(myDate)) {
        var arys = DateStr.split('-');
        myDate = new Date(arys[0], --arys[1], arys[2]);
    }
    return myDate;
}
/* --------------------------------------------------------------------------------------------------- */
//+---------------------------------------------------  
//| 日期合法性验证  
//| 格式为：YYYY-MM-DD或YYYY/MM/DD  
//+---------------------------------------------------
function IsValidDate(DateStr) {
    var r = DateStr.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/);
    if (r == null) {
        return false;
    } else {
        return true;
    }
}

/* --------------------------------------------------------------------------------------------------- */
/* 是否拥有权限 */
function HasntPermission(PermissionNames) {
    var s = PermissionNames.split(",");
    for (var i = 0; i < s.length; i++) {
        if (("," + JsonOriginal.Permissions + ",").indexOf("," + s[i] + ",") > -1) {
            return false;
        }
    }
    return true;
}
function HasPermission(PermissionNames) {
    var s = PermissionNames.split(",");
    for (var i = 0; i < s.length; i++) {
        if (("," + JsonOriginal.Permissions + ",").indexOf("," + s[i] + ",") > -1) {
            return true;
        }
    }
    return false;
}

/* --------------------------------------------------------------------------------------------------- */
/* 是否当前用户 */
function HasntCurrentUser(PersonID) {
    return (JsonOriginal.UserID != "Administrator" && JsonOriginal.UserID != PersonID);
}
function HasCurrentUser(PersonID) {
    return (JsonOriginal.UserID == "Administrator" || JsonOriginal.UserID == PersonID);
}